package com.changli05._map.exer2;

import java.util.*;

public class ProvinceAndCity {
    public static void main(String[] args) {
        Map m = Province.model;
        Set setKey = m.keySet();
        for (Object key : setKey) {
            System.out.print(key+"\t\t");
        }
        Scanner sc = new Scanner(System.in);
        System.out.println();
        String [] city = null;
        while(true){
            System.out.println("请输入你的省份:");
            String province = sc.nextLine();
            city = (String [])m.get(province);
            if(city==null||city.length==0){
                System.out.println("您输入的省份不存在");
            }
            else break;
        }
        for(String c : city){
            System.out.print(c+"\t\t");
        }
        System.out.println("请选择您所在的城市：");
        String cityName = sc.nextLine();
        boolean flag = false;
        for(Object key : city){
            flag = false;
            if(key.equals(cityName)){
                flag = true;
                break;
            }
        }
        if(!flag){
            System.out.println("您输入的城市不存在");
        }
        else {
            System.out.println("登记完成");
        }
        sc.close();
    }


}

class Province {
    public static Map model = new HashMap();
    static{
        model.put("北京",new String []{"北京"});
        model.put("辽宁",new String []{"沈阳","盘锦","铁岭","丹东","大连","锦州","营口"});
        model.put("吉林",new String []{"长春","延边","吉林","白山","白城","四平","松原"});
        model.put("河北",new String []{"承德","沧州","邯郸","邢台","唐山","保定","石家庄"});
        model.put("河南",new String []{"郑州","许昌","开封","洛阳","商丘","南阳","新乡"});
        model.put("山东",new String []{"济南","青岛","日照","临沂","泰安","聊城","德州"});
    }

}